package com.duke.duke.javaagent.base01;

import com.sun.tools.attach.VirtualMachine;

/**
 * java agent 动态加载
 * @author gjy
 * @create 2024-11-22 2:41 PM
 */
public class AttachMainBase {

    public static void main(String[] args) throws Exception {
        System.out.println("动态javaagent加载...");

        //获取进程虚拟机对象
        VirtualMachine attach = VirtualMachine.attach("67022");
        //执行java agent里边的agentmain方法
        attach.loadAgent("/Users/jingyuangao/Documents/code-work/sre-share/javaagent-bash-01/duke-javaagent-base-01/target/gaojy-share-test-agent.jar");


        System.out.println("动态javaagent加载完毕，请去目标进程中查看被注入成功的动态代理标识");
    }
}
